package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.Emp;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {

    List<Map> getJobData();

    List<Map> getGenderData();

    @Insert("insert into emp(id,username,password,name,gender,phone,job,salary,image,entry_date,dept_id,create_time,update_time) " +
            "values(#{id},#{username},#{password},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")//主键自增返回
    void addEmp(Emp emp);

    @Select("<script>\n" +
            "\t select e.*, d.name deptName from emp e left join dept d on e.dept_id=d.id \n" +
            "\t<where>\n" +
            "\t\t<if test='name!=null'>e.name like concat('%', #{name}, '%')</if>\n" +
            "\t\t<if test='gender!=null'>and e.gender=#{gender}</if>\n" +
            "\t\t<if test='begin!=null'>and e.entry_date between #{begin} and #{end}</if>\n" +
            "\t</where>\n" +
            "</script>")
    Page<Emp> pageQuery(String name, Integer gender, LocalDate begin, LocalDate end);


    List<Emp> findAll();


}